package com.heima.kafka.listener;

import com.alibaba.fastjson.JSON;
import com.heima.kafka.pojo.User;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class HelloListener {

    @KafkaListener(topics = "itcast-topic")
    public void onMessage(ConsumerRecord<String, String> record){
        String key = record.key();
        System.out.println("key = " + key);
        String message = record.value();
        if(!StringUtils.isEmpty(message)){
            System.out.println(JSON.parseObject(message, User.class));
        }
    }
}